<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
	<%@taglib uri="/struts-tags"  prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>添加日程</title>
		<link href="css/table.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="js/kindeditor/kindeditor-min.js"></script>
		<script type="text/javascript" src="js/kindeditor/lang/zh_CN.js"></script>
		<script type="text/javascript" src="js/openwindow.js"></script>
		<script type="text/javascript" src="js/file.js"></script>
		<script src="js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
		<script type="text/javascript">
var editor;
KindEditor.ready(function(K) {
	editor = K.create('textarea[name="task.content"]', {
		resizeType : 1,
		allowPreviewEmoticons : false,
		allowImageUpload : false,
		items : [
			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link']
	});
	});
	
	function setValue(value){
	  document.getElementById("array").value = value;
	  var arr = eval(value);
	  var names = "";
	  var ids = "";
	  for(i=0;i<arr.length;i++){
	    ids =  ids + "," + arr[i].value;
	    names = names + "," + arr[i].name;
	  }
	  if(names.length>0){
	    names = names.substring(1);
	    ids =  ids.substring(1);
	  }
	  document.getElementById("names").value=names;
	  document.getElementById("ids").value=ids;
	}
	
	function getOldValue(){
	  var array = document.getElementById("array").value;
	  return array;
	}
	
	function selectUser(){
		var url="getGrouphome.action";
		openWindow(url,700,400);
	}
	
	function saveTask(){
		var reg=/^[0-9]+(\.[0-9]{1})?$/;
		var content =editor.html();
		var startTime1=$("#startTime1").val();
		var startTime2=$("#startTime2").val();
		var alertTime=$("#alertTime").val();
		var title=$("#title").val();
		if(startTime1==''||startTime1=='null'){
			alert('请添加开始时间')
			return;
		}
		if(startTime2==''||startTime2=='null'){
			alert('请添加结束时间')
			return;
		}
		
		if($.trim(alertTime)!=''&&!reg.test(alertTime)){
			alert("时间不规范！只能输入1位小数");
			return;
		}
		if(title==''||title=='null'){
			alert('请添加主题')
			return;
		}
		if(editor.isEmpty()){
			alert("请填写内容");
			return;
		}else if(content.length>2000){
			alert("正文不能超过2000个字符！");
			return;
		}
		var table=$("#filetable").find("input[type=\"checkbox\"]");
		var fileId="";
		for(var i=0;i<table.length;i++){
			fileId+="_"+table[i].value;
		}
		$("#fileArray").val(fileId);
		$("#content").val($.trim(content));
		$.post("saveTask.action",$("form").serialize(),function(data){
			if(data=='success'){
				alert("添加成功！");
				window.close();
				window.opener.location.reload();
			}else{
				alert("添加失败！")
			}
		});
		
	}
	
	function changeCycle(val){
		if(val=='week'){
			document.getElementById("week").style.display="block";
			document.getElementById("monthDay").style.display="none";
		}else if(val=="month"){
			document.getElementById("week").style.display="none";
			document.getElementById("monthDay").style.display="block";
		}else{
			document.getElementById("week").style.display="none";
			document.getElementById("monthDay").style.display="none";
		}
	}
	
	
</script>
	</head>
	<body>
		<table align="center" border="0" cellpadding="0" cellspacing="0"
			width="98%">
			<tbody>
				<tr>
					<td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
					<td style="background: url('image/wsoa_window_002.gif');">
						<table border="0" cellpadding="0" cellspacing="0">
							<tbody>
								<tr>
									<td align="center"
										style="background: url('image/wsoa_window_002.gif');"
										width="10">
										<img src="image/center_19.gif">
									</td>
									<td align="center"
										style="background: url('image/wsoa_window_002.gif');"></td>
									<td></td>
								</tr>
							</tbody>
						</table>
					</td>
					<td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
					
				</tr>
				<tr>
					<td style="background: url('image/wsoa_window_010.gif');" width="1">
						&nbsp;
					</td>
					<td>
						<form  method="post" action="">
							<input type="hidden" name="task.fileId" id="fileArray" value="${task.fileId}">
							<input type="hidden" id="array" >
							<span class="font12"> </span>
							<table style="width: 99%;" align="center">
								<tbody>
									<tr>
										<td>
											<table style="width: 100%;" class="table5 bgcolor5"
												align="center">
												<tbody>
													<tr>
														<td class="table5 bgcolor5" align="right" width="80px">
															<font color="red">*</font>日程时间
														</td>
														<td class="table5">
															<input  name="task.startTime"
															value="${task.startTime }" class="Wdate" id="startTime1" type="text"
															readonly="readonly"
															onclick="WdatePicker()" /> 至
															<input  name="task.endTime" 
																class="Wdate" id="startTime2" type="text" readonly="readonly"
																onclick="WdatePicker({minDate:'#F{$dp.$D(\'startTime1\',{d:0});}'})"
																id="startTime2" />
															
														</td>
														<td class="table5 bgcolor5"  align="right" width="80px">
															循环方式
														</td>
														<td class="table5">
															<table>
																<tr>
																<td>
																 <s:select onchange="changeCycle(this.value)" list="#{'week':'按星期','month':'按月'}" headerKey="" headerValue="--请选择--" name="task.cycle" theme="simple"></s:select>
																</td>
																<td>
																<span id="week" style="display:none;"><s:select  list="#{'1':'星期日','2':'星期一','3':'星期二','4':'星期三','5':'星期四','6':'星期五','7':'星期六'}" name="task.week" theme="simple"></s:select></span>
																</td>
																<td>
																<span id="monthDay" style="display:none;"><s:select  list="monthList" name="task.monthDay" theme="simple"></s:select></span>
																</td>
																</tr>
															</table>
														</td>
													</tr>
													<tr>
													<td class="table5 bgcolor5" align="right" width="80px">
															办理时间
														</td>
														<td class="table5">
															<select name="task.startHour">
																<c:forEach begin="8" end="18" step="1" varStatus="index">
																<option value="${index.current}">${index.current}</option>
																</c:forEach>
															</select>时：
															<select name="task.startMunite">
																<c:forEach begin="0" end="55" step="5" varStatus="index">
																<option value="${index.current}">${index.current}</option>
																</c:forEach>
															</select>分
														</td>
														<td class="table5 bgcolor5" align="right" width="80px">
															短信提醒
														</td>
														<td class="table5"> 
															提前<input name="task.alertTime" id="alertTime" type="text"   style="width: 40px">小时
														</td>
														
													</tr>
													<tr>
														<td  class="table5 bgcolor5" align="right" width="80px">
															<font color="red">*</font>日程主题
														</td>
														<td  class="table5" colspan="3">
															<input name="task.title" id="title" maxlength="50" style="width: 557px;" title="该输入项的最大长度是100" type="text">
														</td>
													</tr>
													<tr>
														<td  class="table5 bgcolor5" align="right" width="80px">
															<font color="red">*</font>日程内容
														</td>
														<td  class="table5" colspan="3">
																<textarea name="task.content" id="content"
																style="width: 100%; height: 300px; visibility: hidden;"></textarea>														</td>
													</tr>
													
													<tr >
														<td class="table5 bgcolor5" align="right" width="80px">
															知会对象
														</td>
														<td class="table5" colspan="3">
															<textarea readonly="readonly" id="names" name="names" style="width:534px;height:20px;">${names }</textarea><br/>
													    	<input type="hidden" id="ids" name="task.notifyUserId" value="${users}">&nbsp;
													    	<a href="javascript:selectUser()">添加联系人</a>
														</td>
													</tr>
												</tbody>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<table style="width: 100%;" class="table5 bgcolor5"
												align="center">
												<tbody>
													<tr>
														<td align="right" width="90px">
															<a href="javascript:file_upload('filetable')">添加附件</a>&nbsp;
															<a href="javascript:fileDel('filetable')">删除</a>
														</td>
														<td>
															<table id="filetable" style=" width:500px">
															</table>
														</td>
													</tr>
												</tbody>
											</table>
										</td>
									</tr>
								</tbody>
							</table>
							<table style="width: 99%;" align="center">
								<tbody>
									<tr>
										<td align="center">
											<span id="errorId"></span>
										</td>
									</tr>
									<tr>
										<td align="center">
											<input accesskey="t" value="提交" style="background: url('image/button_02.gif');" onClick="saveTask();" class="button_02" type="button">
											<input class="button_02" value="取消" accesskey="c" style="background: url('image/button_02.gif');" onClick="window.close();" type="button">
										</td>
									</tr>
								</tbody>
							</table>
						</form>
					</td>
					<td style="background: url('image/wsoa_window_006.gif');" width="1">
						&nbsp;
					</td>
				</tr>
				<tr>
					<td height="1" width="1">
						<img src="image/wsoa_window_009.gif" height="16" width="14">
					</td>
					<td style="background: url('image/wsoa_window_008.gif');"
						height="1"></td>
					<td height="1" width="1">
						<img src="image/wsoa_window_007.gif" height="16" width="12">
					</td>
				</tr>
			</tbody>
		</table>
	</body>
</html>